﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using IRCServer.Utilities;
using IRCServer.Entities;
using IRC.Utilities;
using IRC.Utilities.Entities;

namespace IRCServer
{
    class Program
    {
        static void Main(string[] args)
        {
            Logger.Instance.Verbose = true;
            Dictionary<ArgumentKey, object> arguments;

            Logger.Instance.Info("Starting Routing Daemon...");

            try
            {
                // Load arguments
                arguments = ArgumentsParser.GetArguments(args);
            }
            catch
            {
                Logger.Instance.Error("Invalid arguments");
                return;
            }

            List<NodeConfiguration> config;

            try
            {
                // Load configuration file.
                config = ConfigFileParser.LoadConfigurationFromPath((string)arguments[ArgumentKey.ConfigFilePath]);
            }
            catch
            {
                return;
            }

            Logger.Instance.Debug("Loaded configuration file");

            NodeConfiguration localNode = config.First(n => n.NodeID == (int)arguments[ArgumentKey.NodeID]);

            IRCServer server = new IRCServer(localNode, config);
            server.Start();
        }
    }
}
